﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace TuongLai_Schools
{
    public class cls_DM_Danhhieu
    {
        public DataTable GetAll_Danhhieu()
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select DanhHieuID,TenDanhHieu,GhiChu,isChangeable from DM_DanhHieu");
            return dataTable;
        }
        public bool Insert(clsDM_Danhhieu obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@DanhHieuID", obj.DanhHieuID);
                db.AddParameter("@TenDanhHieu", obj.TenDanhhieu);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("insert into DM_DanhHieu(TenDanhHieu,GhiChu,isChangeable) values(N'" + obj.TenDanhhieu + "',N'" + obj.GhiChu + "','" + obj.isChangeable + "')");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool update(clsDM_Danhhieu obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@DanhHieuID", obj.DanhHieuID);
                db.AddParameter("@TenDanhHieu", obj.TenDanhhieu);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("update DM_DanhHieu set TenDanhHieu=N'" + obj.TenDanhhieu + "',GhiChu=N'" + obj.GhiChu + "',isChangeable='" + obj.isChangeable + "' where DanhHieuID='" + obj.DanhHieuID + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool delete(int Danhhieuid)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@DanhHieuID", Danhhieuid);
                db.ExecuteNonQuery("delete DM_DanhHieu where DanhHieuID='" + Danhhieuid + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
